from django.contrib import admin
from .models import User
from django.contrib.auth.hashers import make_password


# 200:响应成功
# 400:响应失败
# 500:服务出错


@admin.register(User)
class UserAdmin(admin.ModelAdmin):
    fields = ['username', 'mobile', 'longitude', 'latitude', 'busy_score', 'is_forbid', 'is_staff', 'is_active',
              'is_auto_reply']

    search_fields = ['username', 'mobile']
    list_filter = ['is_forbid', 'is_staff', 'date_joined']
    list_display = ['id', 'username', 'mobile', 'longitude', 'latitude', 'busy_score', 'is_forbid', 'is_staff',
                    'is_active', 'is_auto_reply', 'date_joined']
    save_on_top = True
    save_on_bottom = True

    # 保存用户
    def save_model(self, request, obj, form, change):
        obj.user = request.user
        obj.password = make_password(obj.password)
        super().save_model(request, obj, form, change)
